package com.zfast.yugioh.controller;

import com.github.pagehelper.PageInfo;
import com.zfast.forge.common.BaseResult;
import com.zfast.forge.common.Page;
import com.zfast.forge.valid.Create;
import com.zfast.yugioh.model.UserRole;
import com.zfast.yugioh.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户角色关系表
 *
 * @author zgn
 * @email 
 * @date 2022-06-11 15:07:43
 */
@RestController
@RequestMapping("api/userRole")
@Api(tags = {"用户角色关系表Con"})
public class UserRoleController{
    @Resource
    UserRoleService userRoleService;

    @PostMapping({"/list"})
    @ApiOperation(value = "用户角色关系表数据列表", httpMethod = "POST", notes = "获取用户角色关系表列表")
    public BaseResult<PageInfo<UserRole>> list(@RequestBody Page<UserRole> page) {
        BaseResult result=BaseResult.builder()
                .msg("获取用户角色关系表列表成功")
                .data(userRoleService.pageList(page))
                .build();
        return result;
    }

    @GetMapping({"/get/{id}"})
    @ApiOperation(value = "用户角色关系表数据列表", httpMethod = "GET", notes = "获取单个用户角色关系表记录")
    public BaseResult<UserRole> get(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("查询用户角色关系表成功")
                .data(userRoleService.get(id))
                .build();
        return result;
    }

    @PostMapping({"add"})
    @ApiOperation(value = "新增用户角色关系表信息", httpMethod = "POST", notes = "保存用户角色关系表")
    public BaseResult<Integer> add(@RequestBody @Validated(Create.class) UserRole model) {
        BaseResult result=BaseResult.builder()
                .msg("添加用户角色关系表成功")
                .data(userRoleService.insert(model))
                .build();
        return result;
    }

    @PostMapping({"update"})
    @ApiOperation(value = "更新指定id的 用户角色关系表 信息（更新全部信息）", httpMethod = "POST", notes = "更新指定id的 用户角色关系表 信息（更新全部信息）")
    public BaseResult<Integer> update(@RequestBody @ApiParam(name = "userRole", value = "用户角色关系表业务对象", required = true) UserRole model) {
        BaseResult result=BaseResult.builder()
                .msg("更新用户角色关系表成功")
                .data(userRoleService.update(model))
                .build();
        return result;
    }

    @GetMapping({"remove/{id}"})
    @ApiOperation(value = "删除用户角色关系表记录", httpMethod = "GET", notes = "删除用户角色关系表记录")
    public BaseResult<Integer> remove(@ApiParam(name = "id", value = "业务主键", required = true) @PathVariable Integer id) {
        BaseResult result=BaseResult.builder()
                .msg("删除用户角色关系表成功")
                .data(userRoleService.delete(id))
                .build();
        return result;
    }
}
